<template>
    <div class="block">
        <template v-if="()=>keys(value).length">
            <el-button class="right" size="small" @click="Log">变动日志</el-button>
            <el-button class="right" type="primary" size="small" @click="Save">
                保存
            </el-button>
        </template>
        <slot><h2>冷却系数设置</h2></slot>
        <table width="100%" cellspacing="0" cellpadding="2">
            <tr>
                <td />
                <td>开始温度</td>
                <td>结束温度</td>
                <td>使用时间(小时)</td>
            </tr>
            <tr v-for="(obj,key) in list" :key="key">
                <td>{{ Name(obj) }}</td>
                <td v-for="(item,index) in obj" :key="index">
                    <ipt v-model="item.paramValue" />
                </td>
            </tr>
        </table>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {
        value: {
            type: Object,
            default: () => ({})
        }
    },
    data () {
        return {
            list: {}
        }
    },
    computed: {
    },
    watch: {
        value: {
            immediate: true,
            handler (value) {
                console.log(value)
                this.list = value
            }
        }
    },
    created () {

    },
    mounted () {

    },
    methods: {
        Save () {
            const sendData = []
            const _self = this.value
            for (const key in _self) {
                for (const item of _self[key]) {
                    const { uid, paramType, paramName, paramValue } = item
                    sendData.push({ uid, paramType, paramName, paramValue })
                }
            }
            console.log(sendData)
            this.$emit('clic', 'save', sendData, 'cooling')
        },
        Log () {
            this.$emit('clic', 'log', 'cooling')
        },
        Name (obj) {
            if (obj[0]) {
                return obj[0].paramName.replace(/.{4}$/, '')
            }
            return ''
        }

    }
}
</script>

<style scoped lang="stylus">
@import '../styl/public.styl'
table
    table-layout fixed
    min-width 327px
td
    padding 0 20px
    white-space nowrap
</style>
